<template>
  <div>
    <MyHeader
      :background="'blue'"
      title="TabBar案例"
    ></MyHeader>
    <div class="main">
      <!-- 当comName值改变时，页面显示内容随之改变 -->
      <component :is="comName"></component>
    </div>
     <!-- 将数据传给底部导航栏 自定义changeName事件 -->
    <MyTabBar :list='tabList' @changeName='changeFn'></MyTabBar>
  </div>
</template>

<script>
import MyHeader from "./components/MyHeader";
import MyTabBar from './components/MyTabBar.vue'
import MyGoodsList from './views/MyGoodsList.vue'
import MyGoodsSearch from './views/MyGoodsSearch.vue'
import MyUserInfo from './views/MyUserInfo.vue'
export default {
  components: {
    MyTabBar,
    MyHeader,
    MyGoodsList,
    MyGoodsSearch,
    MyUserInfo
  },
  data() {
    return {
      tabList: [
        {
          iconText: "icon-shangpinliebiao",
          text: "商品列表",
          componentName: "MyGoodsList",
        },
        {
          iconText: "icon-sousuo",
          text: "商品搜索",
          componentName: "MyGoodsSearch",
        },
        {
          iconText: "icon-user",
          text: "我的信息",
          componentName: "MyUserInfo",
        },
      ],
      comName:'MyGoodsList'
    };
  },
  methods: {
    // 接收子组件传来的参数，将其赋给变量comName
    changeFn(componentName){
      this.comName = componentName;
    }
  }
};
</script>

<style scoped>
.main{
  padding-top: 45px;
  padding-bottom: 51px;
}
</style>